Skip to content

Conversation

@woutersparre
Copy link

Script that add extra information about petitioners to the petitions screen

If this PR makes an externally-visible change in behavior, please add an appropriate line to changelog.txt.

Script that add extra information about petitioners to the petitions screen
@SilasD
Copy link
Contributor

SilasD commented Dec 17, 2025

I didn't dig into this too deeply, because I ran into the use of gps to find info about the selected petition. Probing the raw screen is not a reasonable way to discover UI state.

-- Capture the initially selected texpos once. This serves as the reference
-- value that identifies the currently highlighted row.
if self.tocheck == nil or self.tocheck == 0 then
self.tocheck = gps.screentexpos_lower[6 * gps.dimy + starty] or 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails in classic ASCII mode (i.e. commercial version graphics turned off).

In that mode, screen cells always have texpos == 0.
(Unless the cell was set by DFHack.)

Comment on lines +47 to +50
-- Helper that returns a localized caste/profession name for a unit
local function get_caste_name(race, caste, profession)
return dfhack.units.getCasteProfessionName(race, caste, profession)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this helper exists. It's a straight passthrough on both call and return.

Is it for possible future customization?

Comment on lines +137 to +143
local u = nil
for _, unit in ipairs(df.global.world.units.active) do
if unit.hist_figure_id == hf_id then
u = unit -- Found the active unit for this histfig
break
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type df.historical_figure has a unit_id field.

local hf = df.historical_figure.find(hf_id)
local u = (hf) and df.unit.find(hf.unit_id) or nil

Comment on lines +36 to +42
local y = starty + i * steps
local idx = (6 * gps.dimy) + y
local tex = gps.screentexpos_lower[idx] or 0

if tex == self.tocheck then
return i -- Found the active petition row
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this will fail in ASCII mode.

-- Determines which petition row is currently selected in the vanilla UI
-- by comparing screen texture positions. This is a heuristic that tracks
-- which row's screen texpos matches the initially captured value.
function getActivePetitionRow(self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should look into df.global.game.main_interface.petitions.

If the open field is true, the other fields are valid. Look at selected_agreement_id and at scroll_position.

Note that, in some UI elements, scroll_position is indexed per 3-row list entry, and in others it is indexed per row. You'll need to figure out which this one uses. (It's a terrible situation.)

(Ignore scrolling, it seems to mean that the scroll bar is being dragged by the mouse.)

Comment on lines +22 to +24
if not gps then
return nil -- If GPS is unavailable, we cannot determine selection
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Harmless but useless, should be removed even if you keep using gps.

df.global.gps is a singleton object created by DF. It will always exist.

for _, hf_id in ipairs(party0.histfig_ids) do histfig_ids[hf_id] = true end
elseif #party0.entity_ids > 0 then
-- Indirect references via an entity
local ent = df.global.world.entities.all[party0.entity_ids[0]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an id is generally not identical to an index, and should not be treated as one. change to:
local ent = df.historical_entity.find(party0.entity_ids[0])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants